import React from 'react';

import {message, notice} from '../Notification/index';
import {BaseModal} from '../Modal/index';

class BaseComponent extends React.Component {

  /**
   *
   * @param type success error info warning
   * @param msg 可以是对象{ message: title, description: config,} 或者 字符串
   * @returns {*}
   */
  showNotice = (type, msg) => notice[type](msg);

  /**
   *
   * @param type success error warning loading
   * @param msg  显示的消息 字符串
   * @param delay  延时关闭时间 0 代表永远不关闭
   * @returns {*}  const hide = this.showMsg('loading', 'Action in progress..', 0);  然后调用 hide(), 可以手动关闭对话框
   */
  showMsg = (type, msg, delay) => message.openMessage(type, msg, delay);

  /**
   * 显示对话框
   * @param type  info success error warning confirm(有两个按钮)
   * @param config
   */
  showDialog = (type, config) => {
    return BaseModal.show(type, config);
  }

  /**
   * 界面跳转
   * @param path 路由地址
   */
  jump = (path) => {
    const {history} = this.props;
    history.push(path);
  }

  /**
   * 获取modal数据
   * @param key  设置的namespace
   * @returns {*}
   */
  getModel = (key) => this.props[key];
}

export default BaseComponent;
